package org.dna.opdracht1;

import java.util.Random;

public class RandomThree extends RandomPerm{

	public RandomThree(String name) {
		super(name);
	}

	// T(N) = O(F(N))
	@Override
	protected int[] randomPerm(int n) {
		int[] array = new int[n];
		for(int i = 0; i < n; i++) {
			array[i] = i;
		}
		
		Random random = new Random();
		for(int i = 0; i < n; i++){
			int randomx = random.nextInt(n);
			swap(array, randomx, array[i]);
		}
		return array;
	}
	
	private void swap(int[] array, int index, int toSwap){
		if(array[index] != array[toSwap]){
			array[index] ^= array[toSwap];
			array[toSwap] ^= array[index];
			array[index] ^= array[toSwap];
		}
	}

}
